<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>敏感词管理</title>
  <link rel="shortcut icon" href="/img/favicon.ico"/>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="/common/layuimini/layui.css" media="all">
  <link rel="stylesheet" href="/common/layuimini/public.css" media="all">
  <style>
    body {
      background-color: #ffffff;
    }
  </style>
</head>
<body>
<div class="layui-form layui-form-pane">

  <input th:value="${sensitive.id}" id="sensitiveId" type="hidden">
  <div class="layui-form-item">
    <label class="layui-form-label">铭感词<span style="color: red">*</span></label>
    <div class="layui-input-block">
      <input type="text" name="value" th:value="${sensitive.value}" lay-verify="required" lay-reqtext="敏感词为空" placeholder="请输入" autocomplete="off" class="layui-input">
    </div>
  </div>

  <div class="layui-form-item">
    <label class="layui-form-label">是否启用</label>
    <div class="layui-input-block">
      <input type="checkbox" th:attr="checked=(${sensitive.enable} == 1 ? true: false)" name="enabled" lay-skin="switch" lay-filter="switch" lay-text="ON|OFF">
    </div>
  </div>

  <div class="layui-form-item" style="margin: 25px 10px;position:absolute;bottom: 0;right: 5%;">
    <div class="layui-input-block">
      <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
      <button type="button" class="layui-btn layui-btn-primary" onclick="javascript:parent.layer.close(parent.layer.getFrameIndex(window.name));">取消</button>
    </div>
  </div>

</div>
</body>
<script type="text/javascript" src="/common/layui/layui.js"></script>
<script type="text/javascript" src="/common/jquery-1.11.3.js"></script>
<script type="text/javascript" src="/common/xm-select/xm-select.js"></script>
<script type="text/javascript" src="/common/blog-ui.js"></script>
<script type="text/javascript">


  layui.use(['table','form','jquery'],function (){
    var form = layui.form;

    form.on('submit(saveBtn)',function (obj){
      var enabled = $("[name='enabled']").is(':checked');
      enabled = (enabled === true) ? 1 : -1;
      const formData = {
        id: $("#sensitiveId").val(),
        value: obj.field.value,
        enable: enabled
      }

      updateSensitive(formData);
    })

    function updateSensitive(data){
      $.ajax({
        url: "/sensitive/admin/updateById",
        contentType: "application/json",
        type: "post",
        dataType: "json",
        data: JSON.stringify(data),
        success: function (res) {
          console.log(res);
          if (res.state) {
            parent.layui.table.reload('currentSensitiveWordsTable');
            parent.layer.closeAll();
          } else {
            Pt.showErrorMsg(res.msg);
          }
        }
      })
    }
  })
</script>
</html>
